package com.iwhalecloud.bss.kite.cucc.service.reception.bo;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.callclient.CallClient;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteContractRootForCoordUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.service.order.DepService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @Description 客户接待，迁移核心包com.iwhalecloud.bss.kite.service.reception.bo.MktContactOrderBO
 * 只重写部分定制包功能！
 * @Author Wei.Junhe
 * @Date 2020/1/17 18:23
 * @Param
 * @return
 */
@Service("localMktContactOrderBO")
public class MktContactOrderBO {

    public Map<String, Object> sendRecReceiptInfo(String contactOrderId, String staffId, String custId,
        String resultDesc) {
        Map<String, Object> params = new HashMap<>();

        String codea = DcPublicCache.getCodea("20191214001", "121401");
        if (KiteStringUtils.isEmpty(codea) || KiteStringUtils.equals(codea, "F")) {
            return params;
        }

        params.put("reqTime", DepService.getReqTime());
        params.put("svcCode", "6010030001");
        params.put("apiCode", "60100300010001");
        params.put("transactionID", DepService.genRequestTransactionId());
        params.put("sign", "对端系统结束营销行为后，调用接口，向营服协同中心回填营销结果");
        params.put("contactOrderId", contactOrderId);
        params.put("contactChlId", "100401");
        params.put("contactBranchId", "15367");
        params.put("contactBranchName", "渠道名称");
        // 接触员工工号
        params.put("contactStaff", staffId);
        // 接触员工姓名
        params.put("contactStaffName", "");
        // yyyy-mm-dd hh24:mi:ss
        params.put("contactDate", "");
        params.put("contactDuration", "");
        params.put("dialingPhone", "");
        params.put("outboundPhone", "");
        params.put("explicitPhone", "");
        params.put("startDate", "");
        params.put("endDate", "");
        params.put("fileUrl", "");
        // 1000-用户 2000-客户
        params.put("targetObjType", "2000");
        params.put("targetObjNbr", custId);
        // 推送账号
        params.put("targetObjAccount", "");
        // 1000-已接触 2000-已办理 3000-有意向 4000-犹豫中 5000-拒绝 6000-接触失败
        params.put("resultNbr", "1000");
        // 接触反馈结果说明
        params.put("resultDesc", resultDesc);
        // 1000-短信邀约 2000-外呼邀约 3000-上门服务 4000-网页推送 5000-接触语音播放
        params.put("contactType", "4000");
        params.put("remark", "");
        // 受理订单id
        params.put("prodOrderId", "");
        // 受理工号
        params.put("prodStaffId", "");

        Object ret = CallClient.extInvoke(KiteContractRootForCoordUtils.SERVICE_RECRECEIPTINFO, params);
        Map<String, Object> svcCont = KiteContractRootForCoordUtils.getSvcCont(ret);
        return svcCont;
    }

    /**
     * Description: <br>
     * 发送短信
     *
     * @param contactId
     * @return <br>
     */
    public DataResult<Map> sendRecommentMsg(String contactId, String staffId, String custId) {
        // 营服协同那边新提供了接口，接口协议在【营服协同ZSmartCoord对外接口说明v3.0.6.pdf】，直接调用接口实现
        Map<String, Object> params = new HashMap<>();
        params.put("contact_order_id", contactId);
        params.put("req_time", DepService.getReqTime());
        params.put("svc_code", "6010040001");
        params.put("api_code", "60100400010001");
        params.put("transaction_id", DepService.genRequestTransactionId());
        params.put("sign", "短信发送接口");
        Object ret = null;
        try {
            ret = CallClient.extInvoke(KiteContractRootForCoordUtils.SERVICE_SENDMSG, params);
        }
        catch (Exception e) {
            ErrorConsts.INF_INVOKE_ERROR.throwOut(e.getMessage());
        }
        Map<String, Object> svcCont = KiteContractRootForCoordUtils.getSvcCont(ret);
        // 营销工单回执
        sendRecReceiptInfo(contactId, staffId, custId, KeyConsts.MARKETING_RECOMMENDATION_ACCEPT);
        if (svcCont != null && KeyConsts.SUCCESS_0.equals(
            Optional.ofNullable(svcCont.get(KiteContractRootForCoordUtils.RESP_CODE)).map(obj -> obj.toString())
                .orElse(""))) {
            return ErrorConsts.SUCCESS.getResult(svcCont);
        }
        return ErrorConsts.SUCCESS.getResult(svcCont);
    }

}
